<%-- 
    Document   : login
    Created on : 2019-9-2, 10:43:27
    Author     : danny
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <script src="js/jquery.min.js"></script>
        <script>
            $(function () {
                $('#btnLogin').click(function () {
                    $.post('<%=request.getContextPath()%>/login.ajax', {
                        userName: $('#userName').val(),
                        pwd: $('#pwd').val()
                    }, function (result, status) {
                        console.log(result);
                        if (result == "success") {
                            location.href = "<%=request.getContextPath()%>/index.html";
                        } else {
                           $('#error').text(result);
                        }
                    });
                });
            });
        </script>
    </head>
    <body>
        <h1>登录表单</h1>
        <form action="<%=request.getContextPath()%>/login.do" method="post">
            用户名：<input name="userName" id="userName" type="text"/><br/>
            密码：<input name="pwd" id="pwd" type="password"/><br/>
            <span style="color: red" id="error"></span><br/>
            <input type="button" value="登录" id="btnLogin"/>
        </form>
    </body>
</html>
